<?php
/**
 * file favorite.php
 * Created on 2015-4-3 下午2:49:39 
 * Create by xiweijie
 */
namespace haibao\www\data;

class Favorite extends \haibao\www\data\BaseMysql{
    const ADD_ATTENTION = 1;
    const DELETE_ATTENTION = 2;
    
    public $relationData = array();
    public function __construct(){
        parent::__construct('\haibao\www\model\data\Favorite');
        $this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_DZ3);
    }
    
    /**
     * 我的收藏  收藏数
     * $aidArr 收藏id数组
     * $type  收藏类型
     */
    public function getCollectionNum($aidArr,$type){
        $sql = 'select count(*) as countNum,id from hb_home_favorite where idtype = %s and id in ('.implode(',',$aidArr).') group by id';
        $result = $this->query($sql,array($type));
        $collectionList = array();
        while($row = $result->fetch_assoc()){
            $collectionList[$row['id']] = $row['countNum'];
        }
        return $collectionList;
    }
    
    public function getiMarkByUid($uid){
        $sql = 'select * from hb_home_favorite where uid=%s';
        $data = $this->query($sql,array($uid));
        $resArr = array();
        $i = 0;
        while ($data->fetch_assoc()){
            $resArr[$i]['Id'] = $data->getData('favid');
            $resArr[$i]['Aid'] = $data->getData('id');
            $resArr[$i]['IdType'] = $data->getData('idtype');
            $resArr[$i]['Title'] = $data->getData('title'); 
            $resArr[$i]['DateLine'] = $data->getData('Dateline');
            $i++;   
        }
        return $resArr;
    }
    
    public function removeByIdAndType($id,$type,$uid){
        $sql = 'delete from hb_home_favorite where id = %s and idtype = %s and uid = %s';
        $result = $this->query($sql,array($id,$type,$uid));
        if($result){
            return $result;
        }else{
            return false;
        }
    }
    
    public function updateReadStatusById($id){
        $sql = 'update hb_home_favorite set isread=%s where favid=%s';
        $this->query($sql,array(\haibao\www\model\data\Favorite::STATUS_READ,$id));
    }
    
    public function getFeatureTitleById($id){
        $this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_ARTICLE);
        $sql = 'select title from zt_special where id=%s';
        $data = $this->query($sql,array($id));
        $result = null;
        while($data->fetch_assoc()){
            $result = $data->getData('title');
        }
        
        return $result;
    }
    
    public function getThreadTitleById($id){
        $sql = 'select subject from hb_forum_thread where tid=%s';
        $data = $this->query($sql,array($id));
        $result = null;
        while($data->fetch_assoc()){
            $result = $data->getData('subject');
        }
        return $result;
    }
    /**
     * 获取帖子的点击数和评论数
     */
    public function getClickCommentNumByThreadIds($theadIds){
    	if(!$theadIds){
    		return false;
    	}
    	$theadIds = (array)$theadIds;
    	$threadIdStr = implode(',', $theadIds);
    	$str = preg_replace('/(\d+)/', '%s', $threadIdStr);
    	$sql = "select tid,views,replies from hb_forum_thread where tid IN (".$str.")";
    	$result = $this->query($sql, $theadIds);
    	$data = array();
    	while ($result->fetch_assoc()){
    			$nums = array(
    					'clickNum'=>$this->formatNum($result->getData('views')),
    					'commentNum'=>$result->getData('replies')
    			);
    			$data[$result->getData('tid')] = $nums;
    	}
    	return $data;
    }
    
    public function getBlogTitleById($id){
        $sql = 'select subject from hb_home_blog where blogid=%s';
        $data = $this->query($sql,array($id));
        $result = null;
        while($data->fetch_assoc()){
            $result = $data->getData('subject');
        }
        return $result;
    }
    /**
     * 获得博客的点击量和评论数
     */
    public function getClickCommentNumByBlogIds($blogIds){
    	if(!$blogIds){
    		return false;
    	}
    	$blogList = array();
    	$blogIds = (array)$blogIds;
    	$blogIds = array_chunk($blogIds, 5);
    	foreach($blogIds as $blogId){
    		$data = $this->getBlogsByBlogIds($blogId);
    		$blogList +=$data;
    	}
    	return $blogList;

    }
    private function getBlogsByBlogIds($blogIds){

    	$blogIdStr = implode(',', $blogIds);
    	$str = preg_replace('/(\d+)/', '%s', $blogIdStr);
    	$sql = "select blogid,viewnum,viewnum_false,comments_count,comments_parise_count,question_count,question_parise_count from hb_home_blog where blogid IN (".$str.")";
    	$result = $this->query($sql, $blogIds);
    	
    	$data = array();
    	while ($result->fetch_assoc()){
    		$nums = array(
    				'clickNum'=>$this->formatNum($result->getData('viewnum_false')),
    				'commentNum'=>$result->getData('comments_count')+$result->getData('comments_parise_count')+$result->getData('question_count')+$result->getData('question_parise_count')
    		);
    		$data[$result->getData('blogid')] = $nums;
    	}
    	return $data;
    }
    
    /**
     * 关注明星\品牌\博主、设计师
     * @param int $uid
     * @param int $id
     * @param int $ids
     */
    public function saveAttention($uid,$id,$type = \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR){
    	$createTime = date('Y-m-d H:i:s');
    	$createTime = \DateTime::createFromFormat('Y-m-d H:i:s', $createTime);
    	switch ($type){
    		case \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR:
    			$this->changeAttentionToCMS(array($id,$uid,$createTime), $type, self::ADD_ATTENTION);
    			break;
    		case \haibao\www\model\data\Favorite::ATTENTION_TYPE_BRAND:
    			$this->changeAttentionToCMS(array($id,$uid,$createTime), $type, self::ADD_ATTENTION);
    			break;
    		case \haibao\www\model\data\Favorite::ATTENTION_TYPE_DESIGNER:
    			$this->changeAttentionToCMS(array($id,$uid,$createTime), $type, self::ADD_ATTENTION);
    			break;
    		case \haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER:
    		    $this->changeAttentionToCMS(array($id,$uid,$createTime), $type, self::ADD_ATTENTION);
    			//$this->saveBlogger($uid, $id);
    			break;
    		case \haibao\www\model\data\Favorite::ATTENTION_TYPE_AMERICAN:
    		    $this->changeAttentionToCMS(array($id,$uid,$createTime), $type, self::ADD_ATTENTION);
    			break;
			case \haibao\www\model\data\Favorite::ATTENTION_TYPE_USER:
			    $this->changeAttentionToCMS(array($id,$uid,$createTime), $type, self::ADD_ATTENTION);
			    break;
    	}
    }
    
    /**
     * 取消关注明星\品牌\博主、设计师
     * @param int $uid
     * @param int $id
     * @param int $ids
     */
    public function clearAttention($uid,$id,$type = \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR){
    	 switch ($type){
    	 	case \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR:
    	 		$this->changeAttentionToCMS(array($id,$uid), $type, self::DELETE_ATTENTION);
    	 		break;
    	 	case \haibao\www\model\data\Favorite::ATTENTION_TYPE_BRAND:
    	 		$this->changeAttentionToCMS(array($id,$uid), $type, self::DELETE_ATTENTION);
    	 		break;
    	 	case \haibao\www\model\data\Favorite::ATTENTION_TYPE_DESIGNER:
    	 		$this->changeAttentionToCMS(array($id,$uid), $type, self::DELETE_ATTENTION);
    	 		break;
    	 	case \haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER:
    	 	    $this->changeAttentionToCMS(array($id,$uid), $type, self::DELETE_ATTENTION);
    			//$this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_DZ3);
    	 		//$sql = 'delete from hb_home_follow where uid=%s and followuid=%s';
    			//$this->query($sql,array($uid,$id));
    	 		break;
	 		case \haibao\www\model\data\Favorite::ATTENTION_TYPE_AMERICAN:
	 		    $this->changeAttentionToCMS(array($id,$uid), $type, self::DELETE_ATTENTION);
	 		    break;
 		    case \haibao\www\model\data\Favorite::ATTENTION_TYPE_USER:
 		        $this->changeAttentionToCMS(array($id,$uid), $type, self::DELETE_ATTENTION);
 		        break;
    	 }
    }
    
    /**
     * 是否关注某明星\品牌\博主、设计师
     * @param int $uid
     * @param array $ids
     * @param int $ids
     */
    public function hasAttention($uid,$ids,$type = \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR){
    	$result = array();
    	switch ($type){
    		case \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR:
    			$this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_CMS);
    			$sql = "select CelebrityId from CelebrityAttentionRecord where UserId=%s and CelebrityId in (".implode(',', $ids).") and RecordType=".\haibao\cms\model\data\CelebrityAttentionRecord::RECORD_TYPE_LIKE." and Status=".\haibao\cms\model\data\CelebrityAttentionRecord::STATUS_ENABLE;
    			$data = $this->query($sql,array($uid));
    			while($data->fetch_assoc()){
    				array_push($result, \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR."_".$data->getData('CelebrityId'));
    			}
    			break;
    		case \haibao\www\model\data\Favorite::ATTENTION_TYPE_BRAND:
    			$this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_CMS);
    			$sql = "select BrandId from BrandAttentionRecord where UserId=%s and BrandId in (".implode(',', $ids).") and RecordType=".\haibao\cms\model\data\BrandAttentionRecord::RECORD_TYPE_LIKE." and Status=".\haibao\cms\model\data\BrandAttentionRecord::STATUS_ENABLE;
    			$data = $this->query($sql,array($uid));
    			while($data->fetch_assoc()){
    				array_push($result, \haibao\www\model\data\Favorite::ATTENTION_TYPE_BRAND."_".$data->getData('BrandId'));
    			}
    			break;
    		case \haibao\www\model\data\Favorite::ATTENTION_TYPE_DESIGNER:
    			$this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_CMS);
    			$sql = "select DesignerId from DesignerAttentionRecord where UserId=%s and DesignerId in (".implode(',', $ids).") and RecordType=".\haibao\cms\model\data\designer\DesignerAttentionRecord::RECORD_TYPE_LIKE." and Status=".\haibao\cms\model\data\designer\DesignerAttentionRecord::STATUS_ENABLE;
    			$data = $this->query($sql,array($uid));
    			while($data->fetch_assoc()){
    				array_push($result, \haibao\www\model\data\Favorite::ATTENTION_TYPE_DESIGNER."_".$data->getData('DesignerId'));
    			}
    			break;
    		case \haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER:
//     			$sql = 'select followuid from hb_home_follow where uid=%s and followuid in ('.implode(',', $ids).')';
//     			$data = $this->query($sql,array($uid));
//     			while($data->fetch_assoc()){
//     				array_push($result, \haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER."_".$data->getData('followuid'));
//     			}
//     			break;
    		    $this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_USER);
    		    $sql = "SELECT AttentionUserId FROM `UserAttentionRecord` WHERE UserId = %s AND AttentionUserId in (".implode(",", $ids).") AND `Status` = ".\haibao\user\model\data\UserAttentionRecord::STATUS_ISOK." AND UserType = ".\haibao\user\model\data\UserAttentionRecord::USERTYPE_BLOG;
    		    $data = $this->query($sql,array($uid));
    		    while($data->fetch_assoc()){
    		        array_push($result, \haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER."_".$data->getData('AttentionUserId'));
    		    }
    		    break;
			case \haibao\www\model\data\Favorite::ATTENTION_TYPE_AMERICAN:
			    $this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_CMS);
			    $sql = "SELECT AmericanId FROM AmericanUserAttention WHERE UserId=%s AND AmericanId in (".implode(",", $ids).") and Status=".\haibao\cms\model\data\americandrama\AmericanUserAttention::STATUS_ENABLE;
			    $data = $this->query($sql,array($uid));
			    while($data->fetch_assoc()){
    				array_push($result, \haibao\www\model\data\Favorite::ATTENTION_TYPE_AMERICAN."_".$data->getData('AmericanId'));
			    }
			    break;
		    case \haibao\www\model\data\Favorite::ATTENTION_TYPE_USER:
		        $this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_USER);
		        $sql = "SELECT AttentionUserId FROM `UserAttentionRecord` WHERE UserId = %s AND AttentionUserId in (".implode(",", $ids).") AND `Status` = ".\haibao\user\model\data\UserAttentionRecord::STATUS_ISOK." AND UserType = ".\haibao\user\model\data\UserAttentionRecord::USERTYPE_USER;
		        $data = $this->query($sql,array($uid));
		        while($data->fetch_assoc()){
    				array_push($result, \haibao\www\model\data\Favorite::ATTENTION_TYPE_USER."_".$data->getData('AttentionUserId'));
		        }
		        break;
    	}
    	return $result;
    }
    
    public function getTotalNumForWap($uid){
    	$sql = "select count(favid) as total from hb_home_favorite where uid=%s and (idtype='aid' or idtype='pid' or idtype='h5')";
    	$data = $this->query($sql,array($uid));
    	while($data->fetch_assoc()){
    		return $data->getData('total');
    	}
    }
    
    private function saveBlogger($uid,$bid){
    	$this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_DZ3);
    	$ids = $uid.','.$bid;
    	$sql = 'select uid,username from hb_common_member where uid in(%s)';
    	$username = '';
    	$fusername = '';
    	$data = $this->query($sql,array($ids));
    	while($data->fetch_assoc()){
    		if($data->getData('uid') == $uid){
    			$username = $data->getData('username');
    		}else{
    			$fusername = $data->getData('username');
    		}
    	}
    	$sql = 'select uid from hb_home_follow where uid=%s and followuid=%s';
    	$data = $this->query($sql,array($bid,$uid));
    	$mutual = 0;
    	while ($data->fetch_assoc()){
    		if($data->getData('uid')){
    			$mutual = 1;
    		}
    	}
    	$this->relationData = array('BlogUserName'=>$fusername);
    	$sql = 'insert into hb_home_follow (uid,username,followuid,fusername,mutual,dateline) values (%s,%s,%s,%s,%s,%s)';
    	$this->query($sql,array($uid,$username,$bid,$fusername,$mutual,time()));
    }    
    
    /**
     * CMS表中关注操作
     * @param array $info   $info[0]为品牌/明星/设计的ID,$info[1]为用户ID
     * @param int $attentionType
     * @param int $actionType  1关注   2取消关注
     */
    private function changeAttentionToCMS($info,$attentionType,$actionType){
    	$this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_CMS);
    	if($actionType == self::ADD_ATTENTION){
    		$info[2] = $info[2]->format("Y-m-d H:i:s");
    		switch ($attentionType){
    			case \haibao\www\model\data\Favorite::ATTENTION_TYPE_BRAND:
    				$sql = "update BrandStatisticalInfo set FansNum=FansNum+1,EditFansNum=EditFansNum+1 where BrandId=%s";
    				$this->query($sql,array($info[0]));
    				$additionalSql = "insert into BrandAttentionRecord(BrandId,UserId,CreateTime) values(%s,%s,%s)";
    				$this->query($additionalSql,$info);
    				break;
    			case \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR:
    				$sql = "update CelebrityRiseCount set FansCount=FansCount+1,EditFansNum=EditFansNum+1 where CelebrityId=%s";
    				$this->query($sql,array($info[0]));
    				$additionalSql = "insert into CelebrityAttentionRecord(CelebrityId,UserId,CreateTime) value(%s,%s,%s)";
    				$this->query($additionalSql,$info);
    				break;
    			case \haibao\www\model\data\Favorite::ATTENTION_TYPE_DESIGNER:
    				$sql = "update DesignerProperty set FansNum=FansNum+1,EditFansNum=EditFansNum+1 where DesignerId=%s";
    				$this->query($sql,array($info[0]));
    				$additionalSql = "insert into DesignerAttentionRecord(DesignerId,UserId,CreateTime) value(%s,%s,%s)";
    				$this->query($additionalSql,$info);
    				break;
				case \haibao\www\model\data\Favorite::ATTENTION_TYPE_AMERICAN:
				    $sql = "update AmericanProperty set FansNum=FansNum+1 where AmericanId=%s";
				    $this->query($sql,array($info[0]));
				    
				    $info[2] = \haibao\cms\model\data\americandrama\AmericanUserAttention::STATUS_ENABLE;
				    $additionalSql = "insert into AmericanUserAttention(AmericanId,UserId,Status) value(%s,%s,%s)";
				    $this->query($additionalSql,$info);
				    break;
			    case \haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER:
			        $this->addAttationBlogerAndUser($info,$actionType,\haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER,\haibao\user\model\data\UserAttentionRecord::USERTYPE_BLOG);
			        break;
			    
		        case \haibao\www\model\data\Favorite::ATTENTION_TYPE_USER:
		            $this->addAttationBlogerAndUser($info,$actionType,\haibao\www\model\data\Favorite::ATTENTION_TYPE_USER,\haibao\user\model\data\UserAttentionRecord::USERTYPE_USER);
		            break;
    		}
    	}else{
    		switch ($attentionType){
    			case \haibao\www\model\data\Favorite::ATTENTION_TYPE_BRAND:
    				$sql = "update BrandStatisticalInfo set FansNum=FansNum-1,EditFansNum=EditFansNum-1 where BrandId=%s";
    				$this->query($sql,array($info[0]));
    				$additionalSql = "update BrandAttentionRecord set Status=".\haibao\cms\model\data\BrandAttentionRecord::STATUS_DISABLE." where BrandId=%s and UserId=%s and RecordType=".\haibao\cms\model\data\BrandAttentionRecord::RECORD_TYPE_LIKE;
    				$this->query($additionalSql,$info);
    				break;
    			case \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR:
    			
    				$sql = "update CelebrityRiseCount set FansCount=FansCount-1,EditFansNum=EditFansNum-1 where CelebrityId=%s";
    				$this->query($sql,array($info[0]));
    				$additionalSql = "update CelebrityAttentionRecord set Status=".\haibao\cms\model\data\CelebrityAttentionRecord::STATUS_DISABLE." where CelebrityId=%s and UserId=%s and RecordType=".\haibao\cms\model\data\CelebrityAttentionRecord::RECORD_TYPE_LIKE;
    				$this->query($additionalSql,$info);
    				break;
    			case \haibao\www\model\data\Favorite::ATTENTION_TYPE_DESIGNER:
    				$sql = "update DesignerProperty set FansNum=FansNum-1,EditFansNum=EditFansNum-1 where DesignerId=%s";
    				$this->query($sql,array($info[0]));
    				$additionalSql = "update DesignerAttentionRecord set Status=".\haibao\cms\model\data\designer\DesignerAttentionRecord::STATUS_DISABLE." where DesignerId=%s and UserId=%s and RecordType=".\haibao\cms\model\data\designer\DesignerAttentionRecord::RECORD_TYPE_LIKE;
    				$this->query($additionalSql,$info);
    				break;
				case \haibao\www\model\data\Favorite::ATTENTION_TYPE_AMERICAN:
				    $sql = "update AmericanProperty set FansNum=FansNum-1 where AmericanId=%s";
				    $this->query($sql,array($info[0]));
				    $additionalSql = "update AmericanUserAttention set Status=".\haibao\cms\model\data\americandrama\AmericanUserAttention::STATUS_DISABLE." where AmericanId=%s and UserId=%s";
				    $this->query($additionalSql,$info);
				    break;
			    case \haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER:
			        
			        $this->addAttationBlogerAndUser($info,$actionType,\haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER,\haibao\user\model\data\UserAttentionRecord::USERTYPE_BLOG);
			        
			        break;
		        case \haibao\www\model\data\Favorite::ATTENTION_TYPE_USER:
		            
		            $this->addAttationBlogerAndUser($info,$actionType,\haibao\www\model\data\Favorite::ATTENTION_TYPE_USER,\haibao\user\model\data\UserAttentionRecord::USERTYPE_USER);
			        
			        break;
    		}
    	}
    }
    /**
     *  $info[0]  被关注用户   $info[1]  当前登录用户
     * @param unknown $info
     * @param unknown $actionType
     * @param unknown $attentionType
     * $userType  用户类型，分为博主和普通用户
     */
    private function addAttationBlogerAndUser($info,$actionType,$attentionType,$userType){
        
        $this->beginTranscation();
        
        $temp = $messageData = array();
    
        $this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_USER);
        
        try{
            if($actionType == self::ADD_ATTENTION){
                
                $additionalSql = "insert into UserAttentionRecord(UserId,AttentionUserId,Status,UserType,IsMutual,CreateTime) value(%s,%s,%s,%s,%s,%s)";
                $this->query($additionalSql,array($info[1],$info[0],\haibao\user\model\data\UserAttentionRecord::STATUS_ISOK,$userType,\haibao\user\model\data\UserAttentionRecord::ISMUTUAL_ISFALSE,$info[2]));
                
                $sql = "SELECT * FROM UserAttentionRecord WHERE UserId =%s AND AttentionUserId=%s AND Status =%s ";
                $result = $this->query($sql,array($info[0],$info[1],\haibao\user\model\data\UserAttentionRecord::STATUS_ISOK));
        
                while ($row = $result->fetch_assoc()){
                    $temp[] = $row;
                }
                if($temp){
                    $additionalSql = "update UserAttentionRecord set IsMutual=".\haibao\user\model\data\UserAttentionRecord::ISMUTUAL_ISOK." where UserId=%s and AttentionUserId=%s and Status=%s";
                    $data = $this->query($additionalSql,array($info[0],$info[1],\haibao\user\model\data\UserAttentionRecord::STATUS_ISOK));
        
                    if ($data){
                        $additionalSql = "update UserAttentionRecord set IsMutual=".\haibao\user\model\data\UserAttentionRecord::ISMUTUAL_ISOK." where UserId=%s and AttentionUserId=%s and Status=%s";
                        $this->query($additionalSql,array($info[1],$info[0],\haibao\user\model\data\UserAttentionRecord::STATUS_ISOK));
                    }
                }
                
                $userName = \haibao\user\business\User::getUserNickNameByUserIds(array($info[1]));
                

                $this->relationData = array('UserName'=>$userName[$info[1]],'FromUserId'=>$info[1],'ToUserId'=>$info[0]);
                
            }else{
                $additionalSql = "update UserAttentionRecord set IsMutual=%s, Status=%s where UserId=%s and AttentionUserId=%s";
                $data = $this->query($additionalSql,array(\haibao\user\model\data\UserAttentionRecord::ISMUTUAL_ISFALSE,\haibao\user\model\data\UserAttentionRecord::STATUS_ISFALSE,$info[1],$info[0]));
                
                if($data){
                    $additionalSql = "update UserAttentionRecord set IsMutual=%s where UserId=%s and AttentionUserId=%s";
                    $this->query($additionalSql,array(\haibao\user\model\data\UserAttentionRecord::ISMUTUAL_ISFALSE,$info[0],$info[1]));
                }
            }
        }catch (\Exception $e) {
            $this->rollback();
            throw $e;
        }
        $this->endTranscation();
    }
}